package fr.afcepf.atod19.voyage.service.implementation;

import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import fr.afcepf.atod19.voyage.dao.interfaces.IDataReservation;
import fr.afcepf.atod19.voyage.entities.Client;
import fr.afcepf.atod19.voyage.entities.Reservation;
import fr.afcepf.atod19.voyage.entities.Voyage;
import fr.afcepf.atod19.voyage.service.interfaces.IServiceReservation;
@Component
@Transactional
public class ServiceReservation implements IServiceReservation {
	
	@Autowired
	private IDataReservation daoReservation;
	
	@Override
	public Reservation faireUneReservation(Voyage v, Client c) {
		Reservation r = new Reservation();
		Date date = new Date();
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		String dateString = dateFormat.format(date);
		r.setDateReservation(dateString);
		r.setDatePaiement(dateString);
		r.setDateAnnulation("00/00/0000");
		Random rand = new Random();
		int i =rand.nextInt(2000-1000) + 1000;
		r.setNumeroReservation(new BigInteger(""+i));
		if(c.getCoordonneesBancaire() == null)
			r.setEtat("reserve");
		else
			r.setEtat("paye");
		r.setClient(c);
		r.setVoyage(v);
		return daoReservation.ajouterReservation(r);
	}

	@Override
	public Reservation modifierUneReservation(Reservation r) {
		// TODO Auto-generated method stubaz
		return null;
	}

	@Override
	public Reservation traiterDemandeAnnulationReservation(
			Integer numReservation) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Reservation consulterUneReservation(Integer numReservation) {
		return daoReservation.consulterReservation(numReservation);
	}

	@Override
	public Reservation faireUneDemandeAnnulation(Reservation r) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Reservation> rechercherReservation(Voyage v, Client c) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Reservation rechercherUneDemandeAnnulation(Voyage v, Client c) {
		// TODO Auto-generated method stub
		return null;
	}

}
